<template>
  <div class="app-container">
    <div class="filter-container">
      <div style="text-align:center;font-size:20px;">
        <span>{{ className }}-本期意见{{ feedback_number }}条</span>
      </div>
    </div>
    <div>
      <el-row v-loading="listLoading">
        <el-col :span="12">
          <div class="top20">课程得分:</div>
          <el-rate
            v-model="total_avg"
            disabled
            show-score
            text-color="#ff9900"
            score-template="{value}"
          >
          </el-rate>
        </el-col>
        <el-col :span="12">
          <div class="top20">老师得分:</div>
          <div v-for="(item, key) of teachers" :key="key">
            <span>{{ item.name }}</span>
            <el-rate
              v-model="item.star"
              disabled
              show-score
              text-color="#ff9900"
              score-template="{value}"
            >
            </el-rate>
          </div>
        </el-col>
        <el-col :span="24">
          <div class="top20">反馈表:</div>
          <ul class="list">
            <li v-for="(item, key) of list" :key="item" @click="showDetail(item, key + 1)">
              <span class="icon-name">{{ key + 1 }}</span>
            </li>
          </ul>
        </el-col>
      </el-row>
    </div>
    <el-drawer
      id="drawer"
      size="50%"
      :title="title"
      :visible.sync="drawer"
      direction="rtl"
    >
      <el-form v-loading="drawLoading" label-position="right" label-width="80px">
        <el-form-item label="班级名称">
          <span>{{ className }}</span>
        </el-form-item>
        <el-form-item label="课程得分">
          <span>{{ detail.course_star }} 分</span>
        </el-form-item>
        <el-form-item label="课程评价">
          <span>{{ detail.course_advice }}</span>
        </el-form-item>
        <el-form-item label="咨询反馈">
          <span>{{ detail.zx_advice }}</span>
        </el-form-item>
        <el-form-item label="老师评价">
          <el-row v-for="item of detail.teachers" :key="item.id">
            <el-divider>{{ item.teacher_name }} - {{ item.teacher_star }} 分</el-divider>
            <el-col :span="24">{{ item.teacher_advice }}</el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="毕业寄语">
          <span>{{ detail.hope }}</span>
        </el-form-item>
      </el-form>
    </el-drawer>
  </div>
</template>

<script>
import {
  fetchList,
  fetchDetail
} from '@/api/feedback'
import waves from '@/directive/waves' // waves directive

export default {
  name: 'FeedbackDetail',
  directives: { waves },
  data() {
    return {
      feedback_number: undefined,
      className: undefined,
      list: [],
      total_avg: 0,
      teachers: [],
      listQuery: {
        class_id: undefined
      },
      listLoading: false,
      detail: {},
      drawer: false,
      drawLoading: false,
      title: ''
    }
  },
  watch: {
    '$route.query.id'() {
      this.init()
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      const { feedback_number, className, id } = this.$route.query
      this.feedback_number = feedback_number
      this.className = className
      this.listQuery.class_id = id
      this.getList()
    },
    async getList() {
      try {
        this.listLoading = true
        const { data: { total_avg, teachers, list }} = await fetchList(this.listQuery)
        this.list = list
        this.teachers = teachers
        this.total_avg = total_avg
        this.listLoading = false
      } catch (e) {
        this.listLoading = false
      }
    },
    async showDetail(id, key) {
      this.title = `反馈表单-${key}`
      this.drawer = true
      try {
        this.drawLoading = true
        const { data } = await fetchDetail(id)
        this.detail = data
        this.drawLoading = false
      } catch (e) {
        this.drawLoading = false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .top20 {
    margin-top:20px;
    margin-bottom:20px;
    font-size: 18px;
  }
  .list li {
    list-style:none;
    margin: 20px;
    height: 85px;
    text-align: center;
    width: 100px;
    float: left;
    font-size: 30px;
    color: #24292e;
    cursor: pointer;
    line-height: 80px;
    border: 1px solid #eee;
  }
</style>
<style>
   #drawer .el-drawer__body {
    overflow-y: scroll
  }
</style>

